
ALTER PROCEDURE [dbo].[AfterMoveAction] 
	@Game_ID numeric(10,0) = null,
	@Player_ID numeric(10,0) = null,
	@Position int = null
AS
BEGIN 
	DECLARE @positionOwner numeric(10,0)
	DECLARE @positionOwnerType nvarchar(20)
	DECLARE @landType nvarchar(20)

	CREATE TABLE #tmpTable
	(
		Player_ID numeric(10,0),
		Land_ID numeric(10,0),
		LandType nvarchar(20),
		PlayerType nvarchar(20)
	)

	INSERT INTO #tmpTable (Player_ID,Land_ID,LandType,PlayerType)
	SELECT pa.Player_ID,pa.[Land_ID],l.[Type],p.[Type]
	  FROM [dbo].[Land] l 
	  left join dbo.PlayerAsset pa on (l.Land_ID = pa.Land_ID and pa.Game_ID = @Game_ID)
	  left join dbo.Player p on (p.Player_ID = pa.Player_ID)
	  where Position = @Position
	
	SELECT
		@positionOwner = #tmpTable.Player_ID,@positionOwnerType = #tmpTable.PlayerType,@landType = #tmpTable.LandType
	FROM 
		#tmpTable
		
	SELECT * FROM #tmpTable
	--DROP TABLE #tmpTable
	
	SELECT * FROM [dbo].[GameAction]
	WHERE IsActive = 'Y' and [LandType] = @landType and [LandOwnerType]=@positionOwnerType
	
END
 
-- [dbo].[AfterMoveAction]  1,3,13